package com.example.demo.base.sysSwitch.service.impl;

import com.example.demo.base.sysSwitch.service.SysSwitchService;
import com.example.demo.constants.RedisKey;
import com.example.demo.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @date2024/3/4
 * @modify -----------------------------------------------------------------------------------------------------
 * |修改单号|修改人员|修改日期|评审人员|修改说明
 * -----------------------------------------------------------------------------------------------------
 * |      |       |      |       |
 * -----------------------------------------------------------------------------------------------------
 */

@Service
public class SysSwitchServiceImpl implements SysSwitchService {

    @Resource
    private RedisUtil redisUtil;
    @Override
    public void open() {
        redisUtil.setKey(RedisKey.SYS_SWITCH, "1");
    }

    @Override
    public void close() {
        redisUtil.setKey(RedisKey.SYS_SWITCH, "0");
    }

    @Override
    public String query() {
        if (!redisUtil.existKey(RedisKey.SYS_SWITCH)){
            redisUtil.setKey(RedisKey.SYS_SWITCH, "0");
        }
        return redisUtil.getValue(RedisKey.SYS_SWITCH);
    }
}
